 var isUpProductBuy = false;
var isDownProductBuy = false;
function toCancle(id) {
	layer.confirm('确定退换里程吗?', function() {
	 
		$.ajax({
     		url:path+"/order/cancle_mileage",
     		data:{"id":id}, 
     		type:"post",
     		dataType:"text",
     		success:function(message){
     			
     			if(message!="-1"){
     				if(message=="1"){
    					layer.msg("里程退还成功!" ,{icon:1,time:1500},function(){
     						
    						window.location.href = window.location.href;
     					});
     				 
     				  
     				}else{
    				layer.msg("无权限操作!" ,{icon:1,time:5000},function(){
 						
    					window.location.href = window.location.href;
					});
     				}
     				
     			}else{
 					layer.alert("里程退还失败!");

     			}
     			
     				 
//	     			document.tbOrderaction.submit();
				/*	$("#cancleId_"+id).html("");
					$("#cancleState_"+id).html("已退还");*/
     		  
     				/*$("#"+no).show();*/
     			
     		},
     		error:function(){
					layer.alert("里程退还失败!");
     		}
     	});	
		
	
	});	
	
	
}
 
function search() {
	var orderNo = document.getElementsByName("orderNo")[0].value;
	 
	var startDate = $('#startDate').val();
	var endDate = $('#endDate').val();
	 
	if (orderNo != '' && isNaN(orderNo)) {
		layer.alert("输入的商品编号有误，请重新输入！");
		return;
	}
	if ((startDate.length != 0 && startDate != '')
			&& (endDate.length != 0 && endDate != '')) {
		var startTime1 = startDate.slice(0, 4) + startDate.slice(5, 7)
				+ startDate.slice(8, 10);
		var endTime1 = endDate.slice(0, 4) + endDate.slice(5, 7)
				+ endDate.slice(8, 10);
		var timeValue1 = endTime1 - startTime1;
		if (timeValue1 < 0) {
			layer.alert("结束时间必须大于或等于开始时间!");
			return;
		}
	}
	// **** 功能 方法 *******
	initPage();
	$(query_order_form).submit();
}
function toIsEmpty() {
	$("#startDate").val("");
	$("#endDate").val("");
	$("#state").val("");	
	$("#orderNo").val("");
	//$('#query_order')[0].reset();
}

function initPage() {
	document.getElementById("page").value = '1';
}
function trims(str) {
	return str.replace(/^\s+|\s+$/g, "");
}

function saveCheckBoxs() {
	var checkBoxList = $("input:checkbox[name='ProducIsBuyId']");
	var list = [];
	checkBoxList.each(function() { // 遍历name=test的多选框
		if ($(this).prop("checked") && !$(this).prop("disabled")) {// 如果选择且为可选
			var state = $(this).prop("checked");
			if (state) {
				var map = {};
				var id_value = $(this).attr("id");
				var id_text = $("#productBuy" + id_value).parent().text();
				map["id"] = id_value;
				map["isBuy"] = id_text.trim() == "已上架" ? "4" : "5";// isBuy;是否上架
																	// ： 5.上架
																	// 4.下架6.过期
				list.push(map);
			}
		}
	});
	var jsonStr = JSON.stringify(list);
	jsonStr = appendJSON(jsonStr);
	$(checkboxs).val(jsonStr);
	if (isUpProductBuy) {
		$(upOrDown).val("1");
	} else if (isDownProductBuy) {
		$(upOrDown).val("0");
	}
}

function appendJSON(jsonStr) {
	if (jsonStr.length < 3) {
		return $(checkboxs).val();
	}
	if ($(checkboxs).val().length > 2) {
		jsonStr = $(checkboxs).val() + "," + jsonStr;
		jsonStr = jsonStr.replace(/\[/g, "");
		jsonStr = jsonStr.replace(/\]/g, "");
		jsonStr = "[" + jsonStr + "]";
	}
	return jsonStr;
}

function idIsInJSON(obj) {
	if ($(checkboxs).val().length < 1) {
		return;
	}
	;
	var arr = eval($(checkboxs).val());
	for (var i = 0; i < arr.length; i++) {
		var newobj = arr[i];
		if (newobj.id == obj.id) {
			$(obj).prop("checked", "checked");
			arr.splice(i, 1);
			i--;
		}
	}
	var jsonStr = JSON.stringify(arr);
	$(checkboxs).val(jsonStr);
}


/*审核*/
 function audit_product(title,url,id,w,h){
	        var index = layer.open({
	            type: 2,
	            title: title,
	            content: url
	        });
	        layer.full(index);
	    }
 
 /*查看*/
 function look_product(title,url,id,w,h){
	        var index = layer.open({
	            type: 2,
	            title: title,
	            content: url
	        });
	        layer.full(index);
	    }
 
 
 /*编辑*/
 function edit_product(title,url,id,w,h){
	        var index = layer.open({
	            type: 2,
	            title: title,
	            content: url
	        });
	        layer.full(index);
	    }
 
 function thisValueForState(obj){
	 
	 $("#cancleMileageInfoQo.state").val(obj);
 }
 
 /*导出*/
 function exportList(path){
	 var form_path= $("#query_order").attr("action");
     $("#query_order").attr("action",path + "/order/export_cancle_mileage_info").submit();
     $("#query_order").attr("action",form_path);
	 
}
 